var RunLayer1 = BaseLayer.extend({
	arr:null,
	scene:null,
	ctor:function (parent) {
		this._super(parent);
		this.init();
	},
	init:/**
			 * 初始化,
			 */
	function () {
		this._super();
		cc.log("RunLayer1初始化");
		// 天平
		this.balance = new Balance(this);
		this.balance.outFama();
		this.balance.outPaper();
		// 左物
		var paper = new Button(this, 10, TAG_PAPER, "#paper.png", this.callback);
		paper.setPosition(920,290);
		paper.setVisible(false);
		// 平衡螺母
		var nut = new Button(this, 10, TAG_NUT, "#nut.png", this.callback);
		nut.setPosition(1103,259);	
		nut.setRotation(170);
		// 物品库
		this.lib = new Lib(this);
		this.lib.init([TAG_LIB_PAPER3,TAG_LIB_BOX,TAG_LIB_SALT,TAG_LIB_BEAKER,TAG_LIB_CYLINDER,TAG_LIB_KETTLE,TAG_LIB_ROD]);
	},
	callback:function (p){
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_NUT:
			this.balance.showDisk();
			break;
		case TAG_PAPER:
			var move = cc.moveTo(1,cc.p(520,220));
			var rotate = cc.rotateTo(0.5, 40);
			var seq = cc.sequence(move,rotate,func);
			p.runAction(seq);
			break;
		case TAG_KETTLE:
			var ber = cc.bezierTo(1, [cc.p(480,250),cc.p(450,220),cc.p(400,230)]);
			var rotate = cc.rotateTo(1, -60);
			var spawn = cc.spawn(ber,rotate);
			var delay = cc.delayTime(1.7);
			var moveBack = cc.moveTo(1,cc.p(700,200));
			var rotate = cc.rotateTo(1, 0);
			var spaw2 = cc.spawn(moveBack,rotate);
			var seq = cc.sequence(spawn, func,delay,spaw2,this.callKill);
			p.runAction(seq);
			break;
		case TAG_CYLINDER:
			var move = cc.moveTo(1,cc.p(460,170));
			var rotate = cc.rotateTo(1, 60);
			var spawn = cc.spawn(move,rotate);
			var delay = cc.delayTime(2);
			var move2 = cc.moveTo(1,cc.p(480,150));
			var rotate2 = cc.rotateTo(1, 0);
			var spawn2 = cc.spawn(move2,rotate2);
			var seq = cc.sequence(spawn, func, delay, spawn2,this.callKill);
			p.runAction(seq);
			break;
		case TAG_ROD:
			this.doRod(p);
		}
	},
	actionDone:function(p){
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_PAPER:
			p.runAction(cc.fadeTo(0.5, 0));
			var keaber = this.getChildByTag(TAG_BEAKER);
			keaber.showSalt(true);
			break;
		case TAG_KETTLE:
			var cylinder = this.getChildByTag(TAG_CYLINDER);
			cylinder.setCascadeOpacityEnabled(true);
			var clyDtl = new cc.Sprite("#cly_dtl.png");
			clyDtl.setPosition(cylinder.width + clyDtl.width * 0.5,cylinder.height * 0.5);
			clyDtl.setOpacity(0);
			clyDtl.setCascadeOpacityEnabled(true);
			cylinder.addChild(clyDtl);
			var fade1 = cc.fadeTo(0.5, 255);
			var delay = cc.delayTime(1.5);
			var fade2 = cc.fadeTo(0.5,0);
			var sequence = cc.sequence(fade1, delay, fade2, this.callNext);
			clyDtl.runAction(sequence);
			var clyLine = new cc.Sprite("#cly_line.png");
			clyDtl.addChild(clyLine);
			clyLine.setPosition(clyDtl.width * 0.5, 0);
			clyLine.runAction(cc.moveBy(1.5,cc.p(0,clyDtl.height * 0.8)));

			var clyLine2 = new cc.Sprite("#cyl.png");
			cylinder.addChild(clyLine2, 1, TAG_CYL_LINE);
			clyLine2.setPosition(cylinder.width * 0.5, 10);
			clyLine2.runAction(cc.moveBy(1.5,cc.p(0,cylinder.height * 0.4)));
			// 水流
			var flowRight = new cc.Sprite("#flow_right.png");
			flowRight.setAnchorPoint(1, 1);
			flowRight.setScale(0);
			flowRight.setRotation(60);
			flowRight.setPosition(10, 220);
			p.addChild(flowRight);
			var seq = cc.sequence(cc.scaleTo(0.5,1),cc.delayTime(1),cc.scaleTo(0.2,0));
			flowRight.runAction(seq);
			break;
		case TAG_CYLINDER:
			// 导入30ml的水
			var beaker = this.getChildByTag(TAG_BEAKER);
			beaker.upLine(true);
			var cylLine = p.getChildByTag(TAG_CYL_LINE);
			if(cylLine != null){
				cylLine.runAction(cc.moveBy(1.5,cc.p(0, -p.height * 0.4 + 10)));	
			}
			// 水流
			var flowLeft = new cc.Sprite("#flow_left.png");
			flowLeft.setAnchorPoint(0, 1);
			flowLeft.setScale(0);
			flowLeft.setRotation(-60);
			flowLeft.setPosition(25, 174);
			p.addChild(flowLeft);
			var seq = cc.sequence(cc.scaleTo(0.5,1),cc.delayTime(1.3),cc.scaleTo(0.2,0));
			flowLeft.runAction(seq);
			break;
		case TAG_ROD:
			// 沉淀消失,1.5s
			var beaker = this.getChildByTag(TAG_BEAKER);
			beaker.waitDiss(true);
			break;
		}
	},
	layerOver:function(){
		
	},
	doRod:/**
			 * 搅拌,静置,等待溶解
			 */
	function(p){
		var rotate = cc.rotateTo(0.3, 45);
		var ber = cc.bezierTo(1.5, [cc.p(480,500),cc.p(600,200),cc.p(535, 180)]);
		var func2 = cc.callFunc(function(){
			// 搅拌，产生波纹
			var beaker = this.getChildByTag(TAG_BEAKER);
			beaker.stir(2);
		}, this);
		var moveSeq = cc.sequence(cc.moveBy(0.2,cc.p(35, 0)),cc.moveBy(0.2,cc.p(-35, 0)));
		var repeat = cc.repeat(moveSeq, 3);
		var ber2 = cc.bezierTo(0.7, [cc.p(600,200),cc.p(480,500),cc.p(400, 400)]);
		var rotate2 = cc.rotateTo(0.3, -45);
		var func = cc.callFunc(this.actionDone, this);
		var seq = cc.sequence(rotate, ber, func2, repeat, func, ber2, rotate2, this.callKill);
		p.runAction(seq);
	},
	destroy:/**
			 * 销毁
			 */
	function(){
		this._super();
	},
	onExit:function(){
		this._super();
	}
});
